home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / gutenprint / mxml.h < prev    next >
Encoding:
C/C++ Source or Header  |  2008-03-15  |  5.8 KB  |  179 lines

  1. /*
  2.  * "$Id: mxml.h,v 1.1 2004/09/17 18:38:01 rleigh Exp $"
  3.  *
  4.  * Header file for mini-XML, a small XML-like file parsing library.
  5.  *
  6.  * Copyright 2003 by Michael Sweet.
  7.  *
  8.  * This program is free software; you can redistribute it and/or
  9.  * modify it under the terms of the GNU Library General Public
  10.  * License as published by the Free Software Foundation; either
  11.  * version 2, or (at your option) any later version.
  12.  *
  13.  * This program is distributed in the hope that it will be useful,
  14.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16.  * GNU General Public License for more details.
  17.  */
  18.  
  19. /**
  20.  * @file gutenprint/mxml.h
  21.  * @brief Mini-XML XML parsing functions.
  22.  */
  23.  
  24. /*
  25.  * Prevent multiple inclusion...
  26.  */
  27.  
  28. #ifndef GUTENPRINT_MXML_H
  29. #  define GUTENPRINT_MXML_H
  30.  
  31. /*
  32.  * Include necessary headers...
  33.  */
  34.  
  35. #  include <stdio.h>
  36. #  include <stdlib.h>
  37. #  include <string.h>
  38. #  include <ctype.h>
  39. #  include <errno.h>
  40.  
  41.  
  42. /*
  43.  * Constants...
  44.  */
  45.  
  46. #  define STP_MXML_WRAP        70    /* Wrap XML output at this column position */
  47. #  define STP_MXML_TAB        8    /* Tabs every N columns */
  48.  
  49. #  define STP_MXML_NO_CALLBACK    0    /* Don't use a type callback */
  50. #  define STP_MXML_NO_PARENT    0    /* No parent for the node */
  51.  
  52. #  define STP_MXML_DESCEND        1    /* Descend when finding/walking */
  53. #  define STP_MXML_NO_DESCEND    0    /* Don't descend when finding/walking */
  54. #  define STP_MXML_DESCEND_FIRST    -1    /* Descend for first find */
  55.  
  56. #  define STP_MXML_WS_BEFORE_OPEN    0    /* Callback for before open tag */
  57. #  define STP_MXML_WS_AFTER_OPEN    1    /* Callback for after open tag */
  58. #  define STP_MXML_WS_BEFORE_CLOSE    2    /* Callback for before close tag */
  59. #  define STP_MXML_WS_AFTER_CLOSE    3    /* Callback for after close tag */
  60.  
  61. #  define STP_MXML_ADD_BEFORE    0    /* Add node before specified node */
  62. #  define STP_MXML_ADD_AFTER    1    /* Add node after specified node */
  63. #  define STP_MXML_ADD_TO_PARENT    NULL    /* Add node relative to parent */
  64.  
  65.  
  66. /*
  67.  * Data types...
  68.  */
  69.  
  70. typedef enum stp_mxml_type_e        /**** The XML node type. ****/
  71. {
  72.   STP_MXML_ELEMENT,                /* XML element with attributes */
  73.   STP_MXML_INTEGER,                /* Integer value */
  74.   STP_MXML_OPAQUE,                /* Opaque string */
  75.   STP_MXML_REAL,                /* Real value */
  76.   STP_MXML_TEXT                /* Text fragment */
  77. } stp_mxml_type_t;
  78.  
  79. typedef struct stp_mxml_attr_s        /**** An XML element attribute value. ****/
  80. {
  81.   char    *name;                /* Attribute name */
  82.   char    *value;                /* Attribute value */
  83. } stp_mxml_attr_t;
  84.  
  85. typedef struct stp_mxml_value_s        /**** An XML element value. ****/
  86. {
  87.   char        *name;            /* Name of element */
  88.   int        num_attrs;        /* Number of attributes */
  89.   stp_mxml_attr_t    *attrs;            /* Attributes */
  90. } stp_mxml_element_t;
  91.  
  92. typedef struct stp_mxml_text_s        /**** An XML text value. ****/
  93. {
  94.   int        whitespace;        /* Leading whitespace? */
  95.   char        *string;        /* Fragment string */
  96. } stp_mxml_text_t;
  97.  
  98. typedef union stp_mxml_value_u        /**** An XML node value. ****/
  99. {
  100.   stp_mxml_element_t    element;    /* Element */
  101.   int            integer;    /* Integer number */
  102.   char            *opaque;    /* Opaque string */
  103.   double        real;        /* Real number */
  104.   stp_mxml_text_t        text;        /* Text fragment */
  105. } stp_mxml_value_t;
  106.  
  107. typedef struct stp_mxml_node_s stp_mxml_node_t;    /**** An XML node. ****/
  108.  
  109. struct stp_mxml_node_s            /**** An XML node. ****/
  110. {
  111.   stp_mxml_type_t    type;            /* Node type */
  112.   stp_mxml_node_t    *next;            /* Next node under same parent */
  113.   stp_mxml_node_t    *prev;            /* Previous node under same parent */
  114.   stp_mxml_node_t    *parent;        /* Parent node */
  115.   stp_mxml_node_t    *child;            /* First child node */
  116.   stp_mxml_node_t    *last_child;        /* Last child node */
  117.   stp_mxml_value_t    value;            /* Node value */
  118. };
  119.  
  120.  
  121. /*
  122.  * C++ support...
  123.  */
  124.  
  125. #  ifdef __cplusplus
  126. extern "C" {
  127. #  endif /* __cplusplus */
  128.  
  129. /*
  130.  * Prototypes...
  131.  */
  132.  
  133. extern void        stp_mxmlAdd(stp_mxml_node_t *parent, int where,
  134.                     stp_mxml_node_t *child, stp_mxml_node_t *node);
  135. extern void        stp_mxmlDelete(stp_mxml_node_t *node);
  136. extern const char    *stp_mxmlElementGetAttr(stp_mxml_node_t *node, const char *name);
  137. extern void        stp_mxmlElementSetAttr(stp_mxml_node_t *node, const char *name,
  138.                                const char *value);
  139. extern stp_mxml_node_t    *stp_mxmlFindElement(stp_mxml_node_t *node, stp_mxml_node_t *top,
  140.                              const char *name, const char *attr,
  141.                      const char *value, int descend);
  142. extern stp_mxml_node_t    *stp_mxmlLoadFile(stp_mxml_node_t *top, FILE *fp,
  143.                           stp_mxml_type_t (*cb)(stp_mxml_node_t *));
  144. extern stp_mxml_node_t    *stp_mxmlLoadString(stp_mxml_node_t *top, const char *s,
  145.                             stp_mxml_type_t (*cb)(stp_mxml_node_t *));
  146. extern stp_mxml_node_t    *stp_mxmlNewElement(stp_mxml_node_t *parent, const char *name);
  147. extern stp_mxml_node_t    *stp_mxmlNewInteger(stp_mxml_node_t *parent, int integer);
  148. extern stp_mxml_node_t    *stp_mxmlNewOpaque(stp_mxml_node_t *parent, const char *opaque);
  149. extern stp_mxml_node_t    *stp_mxmlNewReal(stp_mxml_node_t *parent, double real);
  150. extern stp_mxml_node_t    *stp_mxmlNewText(stp_mxml_node_t *parent, int whitespace,
  151.                          const char *string);
  152. extern void        stp_mxmlRemove(stp_mxml_node_t *node);
  153. extern char        *stp_mxmlSaveAllocString(stp_mxml_node_t *node,
  154.                              int (*cb)(stp_mxml_node_t *, int));
  155. extern int        stp_mxmlSaveFile(stp_mxml_node_t *node, FILE *fp,
  156.                          int (*cb)(stp_mxml_node_t *, int));
  157. extern int        stp_mxmlSaveString(stp_mxml_node_t *node, char *buffer,
  158.                            int bufsize,
  159.                            int (*cb)(stp_mxml_node_t *, int));
  160. extern stp_mxml_node_t    *stp_mxmlWalkNext(stp_mxml_node_t *node, stp_mxml_node_t *top,
  161.                           int descend);
  162. extern stp_mxml_node_t    *stp_mxmlWalkPrev(stp_mxml_node_t *node, stp_mxml_node_t *top,
  163.                           int descend);
  164.  
  165.  
  166. /*
  167.  * C++ support...
  168.  */
  169.  
  170. #  ifdef __cplusplus
  171. }
  172. #  endif /* __cplusplus */
  173. #endif /* !GUTENPRINT_MXML_H */
  174.  
  175.  
  176. /*
  177.  * End of "$Id: mxml.h,v 1.1 2004/09/17 18:38:01 rleigh Exp $".
  178.  */
  179.